var hdtransfersum = (function(){
	
	this.init = function(){
		
		this.updateTransferSum();
		$("#btnTranseSum").click( function(){
			var tempSum = "", str, i, temp;
			str = $("#txtTransferSum").val().split(',');
			for (i = 0; i < str.length; i += 1) {
				tempSum += str[i];
			}
			
        	var newData = {
        		FromAccountID:parseInt($("#selAccountListFrom option:selected").val()),
        		ToAccountID:parseInt($("#selAccountListTo option:selected").val()),
        		Sum:parseFloat(tempSum)
        	};
        	if(newData.FromAccountID !== newData.ToAccountID){
	        	data.transferSum(newData, function(){
	        		hdmain.updateData();
	        	});
	        	$("#txtTransferSum").val("");
	            hdcurrentstate.show();
           }
        });
	};
	this.updateTransferSum = function(){
		data.getAccountList( function (results) {
            var i, num, str = "";
            num = results.rows.length;
            if (num !== 0) {
                for(i=0; i < num; i += 1){
                    str += "<option value='" + results.rows.item(i).AccountID + "'>" + results.rows.item(i).Name + "</option>";
                }
                $("#selAccountListFrom").html(str).selectmenu('refresh');
                $("#selAccountListTo").html(str).selectmenu('refresh');
            }
        });
	};
	this.init();
	return this;
}(hdtransfersum || {}))
